#include<bits/stdc++.h>
#define ll long long
#define Max(a,b,c)  max(a,max(b,c))
#define inf 2100000000
#define fa(i,n,k) for(register int i=k;i<=n;i++)

using namespace std;
string f,add,serv[1005];
int cnt=0;
int n,ser[1005][5];
bool check(string s) {
//	if(s.size()>17)return 0;
	int node=0,k=1,mh=0,jh=0;
	for(int i=s.size()-1; i>=0; i--) {
		if(s[i]>='0'&&s[i]<='9') {
			node+=(s[i]-'0')*k;
//			cout<<(s[i]-'0')*k<<endl;
			k*=10;
//			cout<<node<<endl;
		} else if(s[i]==':') {
//			cout<<node<<endl;
			mh++,k=1;
//			cout<<mh<<endl;
			if(node>65535||mh>1)return 0;
			else node=0;
		} else if(s[i]=='.') {
//			cout<<node<<endl;
			jh++,k=1;
			if(node>255||jh>3)return 0;
			else node=0;
		}
	}
	return 1;
}
bool cserv(string s) {
	for(int i=1; i<=n; i++)if(serv[i]==s)return 0;
	return 1;
}
int con(string s) {
	for(int i=1; i<=n; i++)if(serv[i]==s)return i;
//	cout<<"FAIL\n";
	return 0;
}
void addserv(string s,int i) {
	int rrr=check(s),lll=cserv(s);
	if(rrr&&lll) {
		serv[i]=s;
		cout<<"OK\n";
		return ;
	} else if(!lll) {
		cout<<"FAIL\n";
		return ;
	} else if(!rrr) {
		cout<<"ERR\n";
		return ;
	}
}
void addclie(string s) {
	int t=check(s),l=con(s);
	if(t&&l) {
		cout<<l<<endl;
		return ;
	}  else if(!t) {
		cout<<"ERR\n";
		return ;
	} else if(l==0&&t) {
		cout<<"FAIL\n";
		return ;
	}
}
int main() {
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%d",&n);
	fa(i,n,1) {
		cin>>f>>add;
		if(f[0]=='S')addserv(add,i);
		if(f[0]=='C')addclie(add);
	}
	return 0;
}

